package com.example.recruitment_website.repository;

import com.example.recruitment_website.domain.Collection;
import com.example.recruitment_website.domain.Record;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;
@Repository
public interface CollectionRepository extends JpaRepository<Collection,Integer> {

      @Query(value = "select id,user_id,article_id,article_title,img_url,date  from collection h where h.user_id = ?1 order by h.id desc",nativeQuery = true)
      List<Collection> findByUser_id(int id);

//      @Query(value = "select * from collection a where a.article_id = ?1 and a.user_id = ?2",nativeQuery = true)
//      Record findByIdAndArticle_id(int id, int userId);

      @Transactional
      @Modifying
      @Query(value = "delete from collection where article_id = ?1 and user_id = ?2 ",nativeQuery = true)
      void deleteByArticle_idAndUser_id(int id, int userId);

}
